#!/usr/bin/python3

import os
import sys

'''
    this script is to generate an array of numbers that can map from audio index to
    position index in g_audio_name_array, to avoid the searching loss
'''

if len(sys.argv) < 2:
    print("please input path\n")
    exit(0)
    
dir_path = sys.argv[1]
file_list = [f for f in os.listdir(dir_path) if f.endswith('.wav')]
#print('file_list is', file_list)

index_list = 'XIP_DATA short audio_array_map[] = {'
file_index = 0
#iterate from 0 to biggest number
for i in range(0, int(file_list[-1][5:9])+1):
    if int(file_list[file_index][5:9]) == i:
        index_list += '%d,' % file_index
        file_index += 1
    else:
        index_list += '-1,'

index_list += '};\nint audio_array_map_len = sizeof(audio_array_map) / sizeof(unsigned short);'
print(index_list)



